# -*-coding:utf-8-*-
# -*-coding:utf-8-*-
import re
from utils import read_txt, cut_sent, read_word, read_pos, read_hed
from Syntactic_Analysis import ParseResult

'''
判断 无主句
待完成：兼语句构成无主句
难点： 由“是/有”构成的兼语句 和是字句及有字句 难以区分
'''
def find_key(sentence):
    # 正则表达式寻找关键字 确定句子中含“是”
    pattern_1 = re.compile(r'[\u662f]')  # 是
    if re.findall(pattern_1, sentence):
        return sentence
    return ""

def judge_type(hed_info, modifi_info):
    sbv_info = modifi_info['sbv_info']  # SBV成分
    mt_info = modifi_info['mt_info']    # MT成分
    sbv_h = read_hed(sbv_info, hed_info['word'])  # 修饰HED的SBV成分

    type_lst = ['无主句-（）||动词词组', '无主句-“是”字句', '无主句-“是……的”', '其他句型']
    verb_lst = ['v', 'vd', 'vn']

    type_id = len(type_lst) - 1

    if find_key(hed_info['word']):
        if read_word(mt_info, ['的']):
            type_id = 2
            return type_lst[type_id]
        else:
            type_id = 1
            return type_lst[type_id]
    if hed_info['pos'] in verb_lst:
        type_id = 0
        return type_lst[type_id]
    return type_lst[type_id]



if __name__ == '__main__':
    path = './data/test_wuzhu.txt'
    sentences = read_txt(path)
    for sent in sentences:
        print('*' * 125)
        print(sent)
        fenci_res, pos_res, ddp_res = cut_sent(sent)
        pr = ParseResult(fenci_res, pos_res, ddp_res)
        print('分词：', fenci_res)
        print('词性：', pos_res)
        print('句法：', ddp_res)
        modifi_info = pr.get_modifi_info()
        hed_info = pr.get_hed_info()
        if read_hed(modifi_info['sbv_info'], hed_info['word']) == {}:
            print(judge_type(hed_info, modifi_info))
        else:
            print('非无主句')


